<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js实现计算器</title>
	</head>
	<body>
		<input type="text" name="text" id="txt1" value="" />
		<select id="sel">
			<option value="1">+</option>
			<option value="2">-</option>
			<option value="3">*</option>
			<option value="4">/</option>
		</select>
		<input type="text" name="txt2" id="txt2" value="" />
		<input type="button" id="but" onclick="count()" value="=" />
		<input type="text" name="" id="fruit" value="" />
	</body>
	<script type="text/javascript">
		function count(){
			var x=document.getElementById('txt1').value;
			var s=document.getElementById('sel').value;
			var y=document.getElementById('txt2').value;
			x=parseInt(x);
			y=parseInt(y);
			var f;
			if(s==1){
				f=x+y;
			}else if(s==2){
				f=x-y;
			}else if(s==3){
				f=x*y;
			}else{
				f=x/y;
			}
			document.getElementById("fruit").value=f;
		}
	</script>
</html>






